<?php
class BlockShell extends AppShell
{
    public $uses = array(
        'tbl_account', 'tbl_block_log'
    );
	public function main()
    {
        pr('Block Check Start...');
        while(true)
        {
            $block_info = $this->tbl_block_log->get_date();

            foreach($block_info as $data)
            {
                $block = $data['tbl_block_log'];

                $user_info = $this->tbl_account->get_account($block['a2x_id']);
                $user = $user_info['tbl_account'];

                if( $user['block'] == 0 )
                {
                    if( nowDateTime() >= $block['start_date'] )
                    {
                        $user['block'] = 1;
                        $this->tbl_account->save($user);
                        pr('block on : ' . $block['a2x_id']);
                    }
                }
                else
                {
                    if( nowDateTime() >= $block['end_date'] )
                    {
                        $block['enable'] = 1;
                        $this->tbl_block_log->save($block);

                        $user['block'] = 0;
                        $this->tbl_account->save($user);
                        pr('block off : ' . $block['a2x_id']);
                    }
                }
            }
            sleep(1);
        }
	}
}

